<?php
class Admin_Model_Users extends My_Model_Abstract
{
    protected $_mainTable = 'admin';

    protected $_idFieldName = 'p_admin';

	public function getCollection()
	{
	    $user = Mage::getSingleton('application/users');
		$sql = $this->getAdapter()->select()
		->from($this->_mainTable)
		->where('userid <> ?', 'creabel')
		->where('p_admin <> ?', $user->getId())
		->order('nom');

		return $this->getAdapter()->fetchAll($sql);
	}

	public function getListVentes()
	{
	    $select = $this->getAdapter()->select()
	    ->from('ventes', array('p_ventes', 'dtvente', 'titre'))
	    ->where('dtdeleted = ?', '1900-01-01')
	    ->order('dtvente desc');

	    return $this->getAdapter()->fetchAll($select);
	}

	public function getLimited()
	{
	    if (!parent::getLimited()) {
	        return array();
	    }
	    return explode(',', parent::getLimited());
	}

	public function setLimited($value)
	{
	    if (is_array($value)) {
	        $value = implode(',', $value);
	    }
	    parent::setLimited($value);
	}

	protected function _beforeSave()
	{
	    $userData = $this->getData();
	    if (isset($userData['limited']) && $userData['limited']) {
	        $this->setLimited($userData['limited']);
	    }
	    if ($userData['password']) {
	        $this->setPassword(md5($userData['password']));
	    } else {
	        $this->setPassword($userData['passwordORG']);
	    }
	    $this->unsetData('passwordORG');
	}
}